/*
 * allocations.h
 *
 * Created: 6/13/2013 4:26:51 AM
 *  Author: Tim
 */ 


#ifndef ALLOCATIONS_H_
#define ALLOCATIONS_H_

#include <avr/io.h>



enum Alloc
{
	FEATURE_FREE		= 0,
	FEATURE_UTILIZED	= 1
};

typedef enum TIMER_ALLOC
{
	TIMER_NULL			= 0,
	TIMER_C0			= 1,
	TIMER_C1			= 2,
	TIMER_D0			= 3,
	TIMER_D1			= 4,
	TIMER_E0			= 5
}tmrAlloc_t;

typedef enum AQUISITION_STATE
{
	AQ_UKNOWN_STATE		=0,
	AQ_INIT_STATE		=1,
	AQ_AQUIRE_STATE		=2,
	AQ_SEND_STATE		=3,
	AQ_END_STATE		=4,
	
}daqAqState_t;

typedef struct DAQ_ALLOCATIONS
{
	
	struct StandAlone
	{
		uint8_t	recInfoAck		:1;	//data ready to be written to flash 
		uint8_t	recDataAck		:1; //data ready to be written to flash
		uint8_t	recEOPACK		:1; //data ready to be written to flash
		uint8_t	reserved		:1; //data ready to be written to flash
		uint8_t	aqState			:3;	//used for program state machine
		uint8_t daqStandAlone	:1; //tells what mode the DAQ is in
	}standAlone;
	
	//a '1' signifies that the pin is being used
	struct dioAllocation1
	{
		
		uint8_t	dio8Alloc		:1;
		uint8_t	dio9Alloc		:1;
		uint8_t	dio10Alloc		:1;
		uint8_t	dio11Alloc		:1;
		uint8_t	dio12Alloc		:1;
		uint8_t	dio13Alloc		:1;
		uint8_t reserved		:2;
		
	}dioAlloc1;

	//a '1' signifies that the pin is being used
	struct dioAllocation0
	{
		uint8_t	dio0Alloc		:1;
		uint8_t	dio1Alloc		:1;
		uint8_t	dio2Alloc		:1;
		uint8_t	dio3Alloc		:1;
		uint8_t	dio4Alloc		:1;
		uint8_t	dio5Alloc		:1;
		uint8_t	dio6Alloc		:1;
		uint8_t	dio7Alloc		:1;
		
	}dioAlloc0;
	
	//a '1' signifies that the timer is being used
	struct timerAllocation
	{
		uint8_t timerC0Alloc	:1;
		uint8_t timerC1Alloc	:1;
		uint8_t timerD0Alloc	:1;
		uint8_t timerD1Alloc	:1;
		uint8_t timerE0Alloc	:1;
		uint8_t reserved		:3;
	}timerAlloc;
	
	//a '1' signifies that the analog channel is being used
	struct analogAllocation
	{
		uint8_t analogInCh0Alloc	:1;
		uint8_t analogInCh1Alloc	:1;
		uint8_t analogInCh2Alloc	:1;
		uint8_t analogInCh3Alloc	:1;
		uint8_t analogOutCh0Alloc	:1;
		uint8_t analogOutCh1Alloc	:1;
		uint8_t reserved			:2;
	}analogAlloc;	
	
	//encXalloc signifies if the specific encoder is in use
	//encXTmrAlloc signifies what timer counter the encoder
	//is utilizing for QDEC 
	struct encoderAllocations
	{
		uint16_t enc0Abs		:1;
		uint16_t enc0TmrAlloc	:3;
		uint16_t enc1Abs		:1;
		uint16_t enc1TmrAlloc	:3;
		
	}encAlloc;
	
	//timer allocations of all peripherals
	//4 adc channels
//	tmrAlloc_t adcCh_int[4];
	tmrAlloc_t adc_int;
	//2 dac channels
	tmrAlloc_t dacCh_int[2];
	//dio polling
	tmrAlloc_t dio_int;
	//encoder polling
	tmrAlloc_t enc_int[2];
	
}daqAlloc_t;					

daqAlloc_t daqAlloc;

void allocTimer(tmrAlloc_t tmr);
void unAllocTimer(tmrAlloc_t tmr);

#endif /* ALLOCATIONS_H_ */